import random
from pathlib import Path

from django.http import HttpResponse
from django.shortcuts import render
from utils.sms import send_sms_single
from django.conf import settings


def test_sms_view(request):
    code = random.randrange(1000, 9999)
    print(Path(__file__).resolve().parent.parent)
    tpl=request.GET.get('tpl')
    tpl_id=settings.TENCENT_SMS_TEMPLATE.get(tpl)
    if not tpl_id:
        return HttpResponse('模板不存在！')
    res = send_sms_single('15296532432', tpl_id, [code, ])
    print(res)
    if res['result']:
        return HttpResponse(res['errmsg'])

    return HttpResponse('成功')
